package cn.jishiyu11.xeqb.utils

import android.content.Context
import android.widget.ImageView
import cn.jishiyu11.xeqb.R
import cn.jishiyu11.xeqb.utils.GlidRound.GlideCircleTransform
import cn.jishiyu11.xeqb.utils.GlidRound.GlideRoundTransform
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy

/**
 * Created by jsy_zj on 2018/1/14.
 */
class ImageLoadUtils {
    companion object {
        fun display(context: Context, imageView: ImageView?, url: String) {
            if (imageView == null) {
                throw IllegalArgumentException("argument error")
            }
            Glide.with(context).load(url)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .placeholder(R.drawable.ic_image_loading)
                    .error(R.drawable.ic_empty_picture)
                    .crossFade()
                    .into(imageView)
        }

        fun displayHigh(context: Context, imageView: ImageView?, url: String) {
            if (imageView == null) {
                throw IllegalArgumentException("argument error")
            }
            Glide.with(context).load(url)
                    .asBitmap()
                    .format(DecodeFormat.PREFER_ARGB_8888)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .placeholder(R.drawable.ic_image_loading)
                    .error(R.drawable.ic_empty_picture)
                    .into(imageView)
        }
  fun displayRound(context: Context, imageView: ImageView?, url: String) {
            if (imageView == null) {
                throw IllegalArgumentException("argument error")
            }
      Glide.with(context).load(url)
              .transform(GlideRoundTransform(context))
              .diskCacheStrategy(DiskCacheStrategy.ALL)
//              .centerCrop()
//              .placeholder(R.drawable.ic_image_loading)
              .error(R.drawable.ic_empty_picture)
//              .crossFade()
              .into(imageView)
        }

    }
}